﻿using System;
using System.Collections.Generic;

using System.Text;
using HZ.DrugTrade.Model;

namespace HZ.DrugTrade.IBLL
{
    public delegate void BroadCastEventHandler(string info);
    /// <summary>
    /// 交易系统消息广播系统
    /// </summary>
    public interface IBLL_Message
    {
        void BroadCastMessage(string message);
        event BroadCastEventHandler BroadCastEvent;




        #region 公告公告
        /// <summary>
        /// 发送公告消息
        /// 粒度到角色
        /// (比如 收信人为医疗机构/企业/地区招标中心)
        /// </summary>
        /// <param name="notice"></param>
        /// <returns></returns>
        int AddNotice_Batch(IList<Notice> notices);

        /// <summary>
        /// 获取已发布的公告
        /// </summary>
        /// <param name="where"></param>
        /// <param name="currentpage"></param>
        /// <param name="pagesize"></param>
        /// <param name="totalrecord"></param>
        /// <returns></returns>
        IList<Model.View.Notice> GetNotice(Model.Query.Notice where, int currentpage, int pagesize, out int totalrecord);

        /// <summary>
        /// 获取待审核的公告
        /// </summary>
        /// <param name="where"></param>
        /// <param name="currentpage"></param>
        /// <param name="pagesize"></param>
        /// <param name="totalrecord"></param>
        /// <returns></returns>
        IList<Model.View.Notice> GetAuditNotice(Model.Query.Notice where, int currentpage, int pagesize, out int totalrecord);

        
        /// <summary>
        /// 获取已接收的公告
        /// </summary>
        /// <param name="where"></param>
        /// <param name="currentpage"></param>
        /// <param name="pagesize"></param>
        /// <param name="totalrecord"></param>
        /// <returns></returns>
        IList<Model.View.Notice> GetRecievedNotice(Model.Query.Notice where, int currentpage, int pagesize, out int totalrecord);
        
        /// <summary>
        /// 审核公告
        /// </summary>
        /// <param name="notice"></param>
        /// <returns></returns>
        int UpdateNotice_Audit(Notice notice);

        /// <summary>
        /// 批量删除公告
        /// </summary>
        /// <param name="notices"></param>
        /// <returns></returns>
        int DeleteNotice_Batch(IList<Notice> notices);

        #endregion

        #region 消息
        /// <summary>
        /// 批量发送消息
        /// (消息粒度到机构到机构只有主用户或主用户授权用户才能够发送消息)
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        int AddMessage_Batch(IList<Message> message);


        /// <summary>
        /// 批量发送消息[并保存到发件箱]
        /// (消息粒度到机构到机构只有主用户或主用户授权用户才能够发送消息)
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        int AddMessage_Save_Batch(IList<Message> message);


        /// <summary>
        /// 批量删除消息
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        int DeleteMessage_Batch(IList<Message> message);

        /// <summary>
        /// 修改消息(修改后消息会变成未读状态，发送时间也重新刷新)
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        int UpdateMessage(Message message);

        /// <summary>
        /// 获取消息
        /// (机构ID无需传入)
        /// </summary>
        /// <param name="where"></param>
        /// <param name="currentpage"></param>
        /// <param name="pagesize"></param>
        /// <param name="totalrecord"></param>
        /// <returns></returns>
        IList<Model.View.Message> GetMessage(Model.Query.Message where, int currentpage, int pagesize, out int totalrecord);
        /// <summary>
        /// 获取已经发送的消息
        /// (机构ID无需传入)
        /// </summary>
        /// <param name="where"></param>
        /// <param name="currentpage"></param>
        /// <param name="pagesize"></param>
        /// <param name="totalrecord"></param>
        /// <returns></returns>
        IList<Model.View.Message> GetMessageSent(Model.Query.Message where, int currentpage, int pagesize, out int totalrecord);
        #endregion

        #region 意见反馈
        /// <summary>
        /// 增加一个反馈
        /// </summary>
        /// <param name="feedback"></param>
        /// <returns></returns>
        int AddFeedBack(FeedBack feedback);

        /// <summary>
        /// 批量增加反馈
        /// </summary>
        /// <param name="feedbackList"></param>
        /// <returns></returns>
        int AddFeedBack_Batch(IList<FeedBack> feedbackList);

        /// <summary>
        /// 回复一个反馈
        /// </summary>
        /// <param name="feedback"></param>
        /// <returns></returns>
        int ReplyFeedBack(FeedBack feedback);


        /// <summary>
        /// 批量删除消息
        /// </summary>
        /// <param name="feedbackList"></param>
        /// <returns></returns>
        int DeleteFeedBack_Batch(IList<FeedBack> feedbackList);

        /// <summary>
        /// 刷新反馈状态(已阅读等)
        /// </summary>
        /// <param name="feedback"></param>
        /// <returns></returns>
        int UpdateFeedBack_Status(FeedBack feedback);


        /// <summary>
        /// 察看反馈信息(中心端)
        /// </summary>
        /// <param name="where"></param>
        /// <param name="currentpage"></param>
        /// <param name="pagesize"></param>
        /// <param name="totalrecord"></param>
        /// <returns></returns>
        IList<Model.View.FeedBack> GetFeedBack_Manager(Model.Query.FeedBack where, int currentpage, int pagesize, out int totalrecord);
       
        /// <summary>
        /// 察看反馈信息(发送端(医疗机构企业))
        /// </summary>
        /// <param name="where"></param>
        /// <param name="currentpage"></param>
        /// <param name="pagesize"></param>
        /// <param name="totalrecord"></param>
        /// <returns></returns>
        IList<Model.View.FeedBack> GetFeedBack_Sender(Model.Query.FeedBack where, int currentpage, int pagesize, out int totalrecord);


        #endregion


        #region 预警功能
        /// <summary>
        /// 获取当前预警信息
        /// </summary>
        /// <param name="orgid"></param>
        /// <returns></returns>
        IList<Model.View.WarningResult> GetWarning(string orgid);

        /// <summary>
        /// 批量增加警告
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        int AddWarning(IList<Warning> list);
        /// <summary>
        /// 批量修改警告
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        int UpadateWarning(IList<Warning> list);

        /// <summary>
        /// 获取当前组织的预警设置
        /// </summary>
        /// <returns></returns>
        IList<Warning> GetWarnigSettings();
        #endregion
    }
    /// <summary>
    /// 对广播的客户端封装
    /// </summary>
    public class EventWrapper : MarshalByRefObject
    {
        public event BroadCastEventHandler LocalBroadCastEvent;

        public void BroadCasting(string message)
        {
            LocalBroadCastEvent(message);
        }

        public override object InitializeLifetimeService()
        {
            return null;
        }
    }




}